package com.david.mydemo.framework.config;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AliyunConfig {

    @Value("${aliyun.accessKeyId}")
    private String accessKeyId;

    @Value("${aliyun.accessKeySecret}")
    private String accessKeySecret;

    @Value("${aliyun.oss.endpoint}")
    private String endpoint;

    @Value("${aliyun.acs.region}")
    private String region;

    @Value("${aliyun.acs.product}")
    private String product;

    /**
     * Oss客户端
     * @return
     */
    @Bean
    public OSS ossFileClient() {
        return new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
    }

    /**
     * 图片审核验证Acs客户端
     * @return
     */
    @Bean
    public IAcsClient ossAcsClient() {
        DefaultProfile profile = DefaultProfile.getProfile(region, accessKeyId, accessKeySecret);
        DefaultProfile.addEndpoint(region, product, endpoint); //地区要和图片存储的地区一致
        //实例化client , 重复使用可以提高检测性能
        return new DefaultAcsClient(profile);
    }

    /**
     * 短信验证码Acs客户端
     * @return
     */
    @Bean
    public IAcsClient smsAcsClient() {
        DefaultProfile profile = DefaultProfile.getProfile(region, accessKeyId, accessKeySecret);
        return new DefaultAcsClient(profile);
    }

}
